package com.resou.reader.tinder;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.resou.reader.utils.log.RsLog;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.PushAgent;
import com.umeng.socialize.UMShareAPI;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class MyBaseActivity<P extends SwipePresenter> extends AppCompatActivity {
    Unbinder unbinder;
    protected P presenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initPresenter();
        RsLog.i(getClass().getSimpleName() + "---onCreate()");
        setContentView(getLayoutId());
        unbinder = ButterKnife.bind(this);
        //初始化View
        initView();

        // Umeng push
        PushAgent.getInstance(this).onAppStart();
    }
    private static final String TAG = "BaseActivity-App";
    public abstract int getLayoutId();

    protected abstract void initPresenter();

    /**
     * 初始化View(设置Listener等等)
     */
    protected abstract void initView();

    @Override
    protected void onStart() {
        super.onStart();
        RsLog.i(getClass().getSimpleName() + "---onStart()");
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        RsLog.i(getClass().getSimpleName() + "---onNewIntent()");
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        RsLog.i(getClass().getSimpleName() + "---onStart()");
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
        RsLog.i(getClass().getSimpleName() + "---onPause()");
    }

    @Override
    protected void onStop() {
        super.onStop();
        RsLog.i(getClass().getSimpleName() + "---onStop()");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();

        RsLog.i(getClass().getSimpleName() + "---onDestroy()");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

}
